﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IDAL;

namespace KPIS.GERP.GFMS.DAL
{
    public sealed class D_FIM_Payments_Payinpack : IDAL_FIM_Payments_Payinpack
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        ConvertNullable cn = new ConvertNullable();
        //

        public D_FIM_Payments_Payinpack()
        {

        }

        public M_FIM_Payments_Payinpack GetInfoByPaySeq(int pay_seq)
        {
            string strSQL;
            // string strField = "";
            //string strJoin = "";
            DataTable dtb = null;
            M_FIM_Payments_Payinpack info = new M_FIM_Payments_Payinpack();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@pay_seq", pay_seq);

                strSQL = "SELECT pp.* "
                        + ", s.bgm_source_name, area.work_area_name, c.NameTh as contact_name, ac.bank_acc_name, rs.record_status_name"
                        + " FROM fim_payments_payinpack pp"
                            + " LEFT JOIN bgm_mas_source s ON pp.bgm_source_seq = s.bgm_source_seq"
                            + " LEFT JOIN IcmMasContact c ON pp.contact_seq = c.ConId"
                            + " LEFT JOIN hrm_mp_work_areas area ON pp.work_area_seq = area.work_area_seq"
                            + " LEFT JOIN fim_mas_bank_accounts ac ON pp.bank_acc_seq = ac.bank_acc_seq"
                            + " LEFT JOIN sys_record_status rs ON pp.record_status = rs.record_status"
                        + " WHERE pp.record_status not like @delete_status"
                        + " and pp.pay_seq = @pay_seq";
                //
                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
                if (dtb.Rows.Count > 0)
                {
                    info.pip_id = Convert.ToInt32(dtb.Rows[0]["pip_id"]);
                    info.pay_seq = Convert.ToInt32(dtb.Rows[0]["pay_seq"]);
                    info.bgm_source_seq = Convert.ToInt32(dtb.Rows[0]["bgm_source_seq"]);
                    info.work_area_seq = Convert.ToInt32(dtb.Rows[0]["work_area_seq"]);
                    info.bank_acc_seq = Convert.ToInt32(dtb.Rows[0]["bank_acc_seq"]);
                    info.bgm_year = Convert.ToInt32(dtb.Rows[0]["bgm_year"]);
                    info.pip_date = cn.ConvertNullDateTime(dtb.Rows[0]["pip_date"]);
                    info.pip_no = dtb.Rows[0]["pip_no"].ToString();
                    info.pip_ref_no = dtb.Rows[0]["pip_ref_no"].ToString();
                    info.pip_name = dtb.Rows[0]["pip_name"].ToString();
                    info.contact_seq = cn.ConvertNullInt(dtb.Rows[0]["contact_seq"]);
                    info.contact_name = dtb.Rows[0]["contact_name"].ToString();
                    info.fee_amount = cn.ConvertNullDouble(dtb.Rows[0]["fee_amount"]);
                    info.net_amount = cn.ConvertNullDouble(dtb.Rows[0]["net_amount"]);
                    info.bgm_source_name = dtb.Rows[0]["bgm_source_name"].ToString();
                    info.work_area_name = dtb.Rows[0]["work_area_name"].ToString();
                    info.bank_acc_name = dtb.Rows[0]["bank_acc_name"].ToString();
                    info.record_status = dtb.Rows[0]["RECORD_STATUS"].ToString();
                    info.record_status_name = dtb.Rows[0]["RECORD_STATUS_NAME"].ToString();
                    info.created_by = cn.ConvertNullInt(dtb.Rows[0]["CREATED_BY"]);
                    info.created_when = cn.ConvertNullDateTime(dtb.Rows[0]["CREATED_WHEN"]);
                    info.updated_by = cn.ConvertNullInt(dtb.Rows[0]["UPDATED_BY"]);
                    info.updated_when = cn.ConvertNullDateTime(dtb.Rows[0]["UPDATED_WHEN"]);
                }

            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }

        public IList<M_FIM_Payments_Payinpack> GetFull(Nullable<int> bgm_source_seq
            , Nullable<int> bgm_year, Nullable<int> work_area_seq)
        {
            string strSQL;
           // string strField = "";
            //string strJoin = "";
            DataRowCollection drc = null;
            IList<M_FIM_Payments_Payinpack> infoList = new List<M_FIM_Payments_Payinpack>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(4);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@bgm_source_seq", bgm_source_seq);
                dbManager.AddParameters(2, "@bgm_year", bgm_year);
                dbManager.AddParameters(3, "@work_area_seq", work_area_seq);

                strSQL = "SELECT pp.* "
                        + ", s.bgm_source_name, area.work_area_name "
                        + ", IIF(c.NameTh is null"
                            + ", coalesce(en.prefix_name, '') + ee.first_name + ' ' + ee.last_name "
                            + ", c.NameTh"
                        +") as contact_name "
                        + ", ac.bank_acc_name, rs.record_status_name"
                        + " FROM fim_payments_payinpack pp"
                            + " LEFT JOIN bgm_mas_source s ON pp.bgm_source_seq = s.bgm_source_seq"
                            + " LEFT JOIN IcmMasContact c ON pp.contact_seq = c.ConId" 
                            + " LEFT JOIN hrm_mp_work_areas area ON pp.work_area_seq = area.work_area_seq"
                            + " LEFT JOIN fim_mas_bank_accounts ac ON pp.bank_acc_seq = ac.bank_acc_seq"
                            + " LEFT JOIN sys_record_status rs ON pp.record_status = rs.record_status"
                            + " LEFT JOIN fim_payments pm ON pp.pay_seq = pm.pay_seq"
                            + " LEFT JOIN hrm_ps_employees ee ON ee.emp_seq = pm.emp_seq"
                            + " LEFT JOIN mas_name_prefixes en ON ee.name_prefix_seq = en.name_prefix_seq"
                        + " WHERE pp.record_status not like @delete_status"
                        //  + (bgm_source_seq != null ? " and pp.bgm_source_seq = "+bgm_source_seq : "")
                        //+ (bgm_year != null ? " and pp.bgm_year = " + bgm_year : "")
                        //+ (work_area_seq != null ? " and pp.work_area_seq = "+work_area_seq : "");
                        + (bgm_source_seq != null ? " and pp.bgm_source_seq = @bgm_source_seq" : "")
                        + (bgm_year != null ? " and pp.bgm_year = @bgm_year" : "")
                        + (work_area_seq != null ? " and pp.work_area_seq = @work_area_seq" : "");
                        //
                var dt = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
                drc = dt.Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_FIM_Payments_Payinpack info = new M_FIM_Payments_Payinpack();
                       // info.pip_id = Convert.ToInt32(drc[i]["pip_id"]);
                        info.pay_seq = Convert.ToInt32(drc[i]["pay_seq"]);
                        info.bgm_source_seq = Convert.ToInt32(drc[i]["bgm_source_seq"]);
                        info.work_area_seq = Convert.ToInt32(drc[i]["work_area_seq"]);
                        info.bank_acc_seq = Convert.ToInt32(drc[i]["bank_acc_seq"]);
                        info.bgm_year = Convert.ToInt32(drc[i]["bgm_year"]);
                        info.pip_date = cn.ConvertNullDateTime(drc[i]["pip_date"]);
                        info.pip_no = drc[i]["pip_no"].ToString();
                        info.pip_ref_no = drc[i]["pip_ref_no"].ToString();
                        info.pip_name = drc[i]["pip_name"].ToString();
                        info.contact_seq = cn.ConvertNullInt(drc[i]["contact_seq"]);
                        info.contact_name = drc[i]["contact_name"].ToString();
                        info.fee_amount = cn.ConvertNullDouble(drc[i]["fee_amount"]);
                        info.net_amount = cn.ConvertNullDouble(drc[i]["net_amount"]);
                        info.bgm_source_name = drc[i]["bgm_source_name"].ToString();
                        info.work_area_name = drc[i]["work_area_name"].ToString();
                        info.bank_acc_name = drc[i]["bank_acc_name"].ToString();
                        info.record_status = drc[i]["RECORD_STATUS"].ToString();
                        info.record_status_name = drc[i]["RECORD_STATUS_NAME"].ToString();
                        info.created_by = cn.ConvertNullInt(drc[i]["CREATED_BY"]);
                        info.created_when = cn.ConvertNullDateTime(drc[i]["CREATED_WHEN"]);
                        info.updated_by = cn.ConvertNullInt(drc[i]["UPDATED_BY"]);
                        info.updated_when = cn.ConvertNullDateTime(drc[i]["UPDATED_WHEN"]);
                        infoList.Add(info);
                    }
                }

            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public bool InsertList(IList<M_FIM_Payments_Payinpack> lst) {
            bool ret = false;

            int Seq = 0;
            string strSeq = "";
            string strSql = "";
            try
            {
                List<M_FIM_Payments> lst_pay = new List<M_FIM_Payments>();
                ret = true;
                dbManager.Open();
                dbManager.CreateParameters(16);
                dbManager.BeginTransaction();
                foreach (M_FIM_Payments_Payinpack info in lst)
                {
                    dbManager.AddParameters(0, "@pay_seq", info.pay_seq);
                    dbManager.AddParameters(1, "@bgm_source_seq", info.bgm_source_seq);
                    dbManager.AddParameters(2, "@work_area_seq", info.work_area_seq);
                    dbManager.AddParameters(3, "@bgm_year", info.bgm_year);
                    //dbManager.AddParameters(4, "@pip_id", info.pip_id);
                    dbManager.AddParameters(4, "@pip_date", info.pip_date.HasValue ? info.pip_date : null);
                    dbManager.AddParameters(5, "@pip_no", info.pip_no);
                    dbManager.AddParameters(6, "@pip_name", info.pip_name);
                    dbManager.AddParameters(7, "@contact_seq", info.contact_seq);
                    dbManager.AddParameters(8, "@pip_ref_no", info.pip_ref_no);
                    dbManager.AddParameters(9, "@bank_acc_seq", info.bank_acc_seq);
                    dbManager.AddParameters(10, "@fee_amount", info.fee_amount);
                    dbManager.AddParameters(11, "@net_amount", info.net_amount);
                    dbManager.AddParameters(12, "@record_status", (string.IsNullOrEmpty(info.record_status) ? SystemInfo._WorkRecordStatus : info.record_status));
                    dbManager.AddParameters(13, "@created_by", info.created_by);
                    dbManager.AddParameters(14, "@created_when", info.created_when);
                    dbManager.AddParameters(15, "@to_bank_acc_id", info.to_bank_acc_id);

                    strSql = "INSERT INTO fim_payments_payinpack"
                        + "(bgm_source_seq, work_area_seq, bgm_year, pay_seq"
                        + ", pip_date, pip_no, pip_name, contact_seq, pip_ref_no"
                        + ", bank_acc_seq, fee_amount, net_amount, record_status, created_by, created_when, to_bank_acc_id)"
                        + " VALUES(@bgm_source_seq, @work_area_seq, @bgm_year, @pay_seq"
                        + ", @pip_date, @pip_no, @pip_name, @contact_seq, @pip_ref_no"
                        + ", @bank_acc_seq, @fee_amount, @net_amount, @record_status, @created_by, @created_when, @to_bank_acc_id);"
                     + " select scope_identity()";
                    strSeq = dbManager.ExecuteDataSet(CommandType.Text, strSql).Tables[0].Rows[0][0].ToString();
                    
                    if (!String.IsNullOrEmpty(strSeq.Trim()))
                    {
                        Seq = Convert.ToInt32(strSeq);
                        if (Seq > 0)
                        {
                            M_FIM_Payments info_pay = new M_FIM_Payments();
                            info_pay.pay_seq = info.pay_seq;
                            info_pay.real_pay_date = info.pip_date;
                            info_pay.updated_by = info.created_by;
                            info_pay.updated_when = info.created_when;
                            info_pay.post_pay_seq = Seq;
                            lst_pay.Add(info_pay);
                            ret &= true;
                        }
                        else
                        {
                            ret &= false;
                        }
                    }
                }
                
                if (ret)
                {
                    dbManager.CommitTransaction();
                    if (lst_pay.Count > 0) {
                        dbManager.Dispose();
                        UpdatePayments(lst_pay);
                    }
                }
                else
                    dbManager.RollBackTransaction();
            }
            catch
            {
                dbManager.RollBackTransaction();
                throw;
            }
            finally
            {
                //if (dbManager.Connection.State == ConnectionState.Closed)
                //dbManager.Dispose();
            }
            return ret;
        }

        public bool UpdateList(IList<M_FIM_Payments_Payinpack> lst)
        {
            bool ret = false;

            int Seq = 0;
            string strSql = "";
            DataRowCollection drc = null;
            try
            {
                List<M_FIM_Payments> lst_pay = new List<M_FIM_Payments>();
                ret = true;
                dbManager.Open();
                
                foreach (M_FIM_Payments_Payinpack info in lst)
                {
                    dbManager.CreateParameters(16);
                    dbManager.AddParameters(0, "@pip_ref_no", info.pip_ref_no);
                    dbManager.AddParameters(1, "@updated_when", info.updated_when);
                    dbManager.AddParameters(2, "@updated_by", info.updated_by);
                    dbManager.AddParameters(3, "@net_amount", info.net_amount);
                    dbManager.AddParameters(4, "@fee_amount", info.fee_amount);
                    dbManager.AddParameters(5, "@bank_acc_seq", info.bank_acc_seq);
                    dbManager.AddParameters(6, "@pip_date", info.pip_date.HasValue ? info.pip_date : null);
                    dbManager.AddParameters(7, "@pip_name", info.pip_name);
                    dbManager.AddParameters(8, "@pip_no", info.pip_no);
                    dbManager.AddParameters(9, "@pay_seq", info.pay_seq);
                    dbManager.AddParameters(10, "@record_status", SystemInfo._WorkRecordStatus);
                    dbManager.AddParameters(11, "@bgm_source_seq", info.bgm_source_seq);
                    dbManager.AddParameters(12, "@work_area_seq", info.work_area_seq);
                    dbManager.AddParameters(13, "@bgm_year", info.bgm_year);
                    dbManager.AddParameters(14, "@created_by", info.updated_by);
                    dbManager.AddParameters(15, "@created_when", info.updated_when);

                    strSql = "SELECT * FROM fim_payments_payinpack"
                            + " WHERE pip_ref_no = @pip_ref_no and pay_seq = @pay_seq";

                    drc = dbManager.ExecuteDataSet(CommandType.Text, strSql).Tables[0].Rows;
                    if (drc.Count > 0)
                    {
                        strSql = "UPDATE fim_payments_payinpack"
                                + " set pip_no = @pip_no"
                                + ", pip_name = @pip_name"
                                + ", pip_date = @pip_date"
                                + ", bank_acc_seq = @bank_acc_seq"
                                + ", fee_amount = @fee_amount"
                                + ", net_amount = @net_amount"
                                + ", updated_by = @updated_by"
                                + ", updated_when = @updated_when"
                                + ", record_status = @record_status"
                                + " WHERE pip_ref_no = @pip_ref_no and pay_seq = @pay_seq";

                        Seq = dbManager.ExecuteNonQuery(CommandType.Text, strSql);

                        if (Seq > 0)
                        {
                            M_FIM_Payments info_pay = new M_FIM_Payments();
                            info_pay.pay_seq = info.pay_seq;
                            info_pay.real_pay_date = info.pip_date;
                            info_pay.updated_by = info.created_by;
                            info_pay.updated_when = info.created_when;
                            info_pay.post_pay_seq = Seq;
                            lst_pay.Add(info_pay);

                            if (lst_pay.Count > 0) UpdatePayments(lst_pay);
                        }
                        
                    }
                    else {
                        List<M_FIM_Payments_Payinpack> lstp = new List<M_FIM_Payments_Payinpack>();
                        lstp.Add(info);
                        InsertList(lstp);
                    }
                }
                
            }
            catch
            {               
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
            return ret;
        }

        public bool UpdatePayments(IList<M_FIM_Payments> lst)
        {
            bool ret = false;
            int result = 0;
            string strSQL;
            try
            {
                ret = true;
                dbManager.Open();
                dbManager.CreateParameters(5);
                dbManager.BeginTransaction();
                foreach (M_FIM_Payments info in lst)
                {
                    dbManager.AddParameters(0, "@pay_seq", info.pay_seq);
                    dbManager.AddParameters(1, "@real_pay_date", info.real_pay_date);
                    dbManager.AddParameters(2, "@post_pay_seq", info.post_pay_seq);
                    dbManager.AddParameters(3, "@updated_by", info.updated_by);
                    dbManager.AddParameters(4, "@updated_when", info.updated_when);

                    strSQL = "UPDATE fim_payments"
                        + " SET real_pay_date = @real_pay_date"
                        + ", post_pay_seq = @post_pay_seq"
                        + ", updated_by = @updated_by"
                        + ", updated_when = @updated_when"
                        + " WHERE pay_seq = @pay_seq";

                    result = dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
                    if (result > 0)
                        ret &= true;
                    else
                        ret &= false;
                }
                if (ret)
                    dbManager.CommitTransaction();
                else
                    dbManager.RollBackTransaction();
            }
            catch
            {
                dbManager.RollBackTransaction();
                throw;
            }
            finally
            {
                //dbManager.Dispose();
            }
            return ret;
        }

        public string Insert(M_FIM_Payments_Payinpack info)
        {
            string strSQL;
            string strSeq = "";
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(15);
                dbManager.BeginTransaction();

                dbManager.AddParameters(0, "@pay_seq", info.pay_seq);
                dbManager.AddParameters(1, "@bgm_source_seq", info.bgm_source_seq);
                dbManager.AddParameters(2, "@work_area_seq", info.work_area_seq);
                dbManager.AddParameters(3, "@bgm_year", info.bgm_year);
                //dbManager.AddParameters(4, "@pip_id", info.pip_id);
                dbManager.AddParameters(4, "@pip_date", info.pip_date.HasValue ? info.pip_date:null);
                dbManager.AddParameters(5, "@pip_no", info.pip_no);
                dbManager.AddParameters(6, "@pip_name", info.pip_name);
                dbManager.AddParameters(7, "@contact_seq", info.contact_seq);
                dbManager.AddParameters(8, "@pip_ref_no", info.pip_ref_no);
                dbManager.AddParameters(9, "@bank_acc_seq", info.bank_acc_seq);
                dbManager.AddParameters(10, "@fee_amount", info.fee_amount);
                dbManager.AddParameters(11, "@net_amount", info.net_amount);
                dbManager.AddParameters(12, "@record_status", (string.IsNullOrEmpty(info.record_status) ? SystemInfo._WorkRecordStatus : info.record_status));
                dbManager.AddParameters(13, "@created_by", info.created_by);
                dbManager.AddParameters(14, "@created_when", info.created_when);

                strSQL = "INSERT INTO fim_payments_payinpack"
                    + "(bgm_source_seq, work_area_seq, bgm_year, pay_seq"
                    + ", pip_date, pip_no, pip_name, contact_seq, pip_ref_no"
                    + ", bank_acc_seq, fee_amount, net_amount, record_status, created_by, created_when)"
                    + " VALUES(@bgm_source_seq, @work_area_seq, @bgm_year, @pay_seq"
                    + ", @pip_date, @pip_no, @pip_name, @contact_seq, @pip_ref_no"
                    + ", @bank_acc_seq, @fee_amount, @net_amount, @record_status, @created_by, @created_when);"
                +" select scope_identity();";
                strSeq = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows[0][0].ToString();

                dbManager.CommitTransaction();
                //return strSeq;
            }
            catch
            {
                dbManager.RollBackTransaction();
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }

            return strSeq;
        }

        public void Update(M_FIM_Payments_Payinpack info)
        {           
            string strSQL;
            DataRowCollection drc = null;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(9);

                dbManager.AddParameters(0, "@pip_ref_no", info.pip_ref_no);
                dbManager.AddParameters(1, "@updated_when", info.updated_when);
                dbManager.AddParameters(2, "@updated_by", info.updated_by);
                dbManager.AddParameters(3, "@net_amount", info.net_amount);
                dbManager.AddParameters(4, "@fee_amount", info.fee_amount);
                dbManager.AddParameters(5, "@bank_acc_seq", info.bank_acc_seq);
                dbManager.AddParameters(6, "@pip_date", info.pip_date.HasValue ? info.pip_date : null);
                dbManager.AddParameters(7, "@pip_name", info.pip_name);
                dbManager.AddParameters(8, "@pip_no", info.pip_no);

                strSQL = "UPDATE fim_payments_payinpack"
                        + " set pip_no = @pip_no"
                        + ", pip_name = @pip_name"
                        + ", pip_date = @pip_date"
                        + ", bank_acc_seq = @bank_acc_seq"
                        + ", fee_amount = @fee_amount"
                        + ", net_amount = @net_amount"
                        + ", updated_by = @updated_by"
                        + ", updated_when = @updated_when"
                        + " WHERE pip_ref_no = @pip_ref_no";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);

                strSQL = "SELECT * FROM fim_payments_payinpack"
                            + " WHERE pip_ref_no = @pip_ref_no";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;

                List<M_FIM_Payments> lst_pay = new List<M_FIM_Payments>();
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_FIM_Payments info_pay = new M_FIM_Payments();
                        info_pay.pay_seq = Convert.ToInt32(drc[i]["pay_seq"]);
                        info_pay.real_pay_date = info.pip_date;
                        info_pay.post_pay_seq = Convert.ToInt32(drc[i]["pip_id"]);
                        info_pay.updated_by = info.updated_by;
                        info_pay.updated_when = info.updated_when;
                        lst_pay.Add(info_pay);
                    }
                    if (lst_pay.Count > 0) UpdatePayments(lst_pay);
                }
                

            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public void Delete2(M_FIM_Payments_Payinpack info)
        {
            string strSQL;
            int Seq = 0;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(5);
                dbManager.AddParameters(0, "@pip_ref_no", info.pip_ref_no);
                dbManager.AddParameters(1, "@pay_seq", info.pay_seq);
                dbManager.AddParameters(2, "@record_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(3, "@updated_by", info.updated_by);
                dbManager.AddParameters(4, "@updated_when", info.updated_when);

                strSQL = "UPDATE fim_payments_payinpack"
                    + " SET record_status = @record_status"
                    + ", updated_by = @updated_by"
                    + ", updated_when = @updated_when"
                    + " WHERE pip_ref_no = @pip_ref_no AND pay_seq = @pay_seq";

                Seq = dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
                if (Seq > 0) {
                    IList<M_FIM_Payments> lstp = new List<M_FIM_Payments>();
                    M_FIM_Payments i = new M_FIM_Payments();
                    i.pay_seq = info.pay_seq;
                    i.real_pay_date = null;
                    i.post_pay_seq = null;
                    i.updated_by = info.updated_by;
                    i.updated_when = info.updated_when;
                    lstp.Add(i);
                    if (lstp.Count > 0) UpdatePayments(lstp);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public void Delete(M_FIM_Payments_Payinpack info)
        {
            string strSQL;
            try
            {
                IList<M_FIM_Payments_Payinpack> lst = GetFull(info.bgm_source_seq, info.bgm_year, info.work_area_seq);
                lst = lst.Where(p => p.pip_ref_no == info.pip_ref_no).ToList();
                IList<M_FIM_Payments> lstp = new List<M_FIM_Payments>();
                foreach (M_FIM_Payments_Payinpack item in lst) {
                    M_FIM_Payments i = new M_FIM_Payments();
                    i.pay_seq = item.pay_seq;
                    i.real_pay_date = null;
                    i.post_pay_seq = null;
                    i.updated_by = info.updated_by;
                    i.updated_when = info.updated_when;
                    lstp.Add(i);
                }
                if (lstp.Count > 0) UpdatePayments(lstp);

                dbManager.Open();
                dbManager.CreateParameters(4);
                    dbManager.AddParameters(0, "@pip_ref_no", info.pip_ref_no);
                    dbManager.AddParameters(1, "@record_status", SystemInfo._DeleteRecordStatus);
                    dbManager.AddParameters(2, "@updated_by", info.updated_by);
                    dbManager.AddParameters(3, "@updated_when", info.updated_when);

                    strSQL = "UPDATE fim_payments_payinpack"
                        + " SET record_status = @record_status"
                        + ", updated_by = @updated_by"
                        + ", updated_when = @updated_when"
                        + " WHERE pip_ref_no = @pip_ref_no";
                
                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        //public IList<M_FIM_Payments> GetList(Nullable<int> bgm_source_seq
        //    , Nullable<int> bgm_year, Nullable<int> work_area_seq, Nullable<int> event_seq)
        //{
        //    string strSQL;
        //    DataRowCollection drc = null;
        //    IList<M_FIM_Payments> infoList = new List<M_FIM_Payments>();
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(5);

        //        dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
        //        dbManager.AddParameters(1, "@bgm_source_seq", bgm_source_seq);
        //        dbManager.AddParameters(2, "@bgm_year", bgm_year);
        //        dbManager.AddParameters(3, "@work_area_seq", work_area_seq);
        //        dbManager.AddParameters(4, "@event_seq", event_seq);

        //        strSQL = "SELECT transfer_seq"
        //            + ", concat(coalesce(ref_no, ''), ' - ', coalesce(transfer_name, '')) as transfer_name"
        //            + " FROM fim_transfers"
        //            + " WHERE record_status not like @delete_status";

        //        drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
        //        if (drc.Count > 0)
        //        {
        //            for (int i = 0; i < drc.Count; i++)
        //            {
        //                M_FIM_Payments info = new M_FIM_Payments();
        //                info.pay_seq = Convert.ToInt32(drc[i]["pay_seq"]);
        //                info.pay_name = drc[i]["pay_name"].ToString();
        //                infoList.Add(info);
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw (ex);
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return infoList;
        //}

        //public M_FIM_Payments GetInfo(int seq)
        //{
        //    string strSQL;
        //    DataRowCollection drc = null;
        //    M_FIM_Payments info = new M_FIM_Payments();
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(1);

        //        dbManager.AddParameters(0, "@seq", seq);

        //        strSQL = "SELECT pay.pay_seq, pay.bgm_source_seq, pay.work_area_seq, pay.bgm_year"
        //            + ", pay.event_seq, pay.pay_date, pay.real_pay_date, pay.ref_no"
        //            + ", pay.receipt_no, pay.receipt_name, pay.pay_name, pay.method_seq"
        //            + ", pay.money_req_seq, pay.petition_seq, pay.petition_dtls_seq"
        //            + ", pay.emp_seq, pay.contact_seq, pay.contact_person_seq, pay.bidder_seq, pay.po_seq"
        //            + ", pay.amount, pay.vat_rate, pay.vat, pay.tax_rate, pay.tax"
        //            + ", pay.post_pay_seq, pay.tax_pay_seq"

        //            + ", s.bgm_source_name, area.work_area_name"
        //            + ", concat(np.prefix_short, emp.first_name, ' ', emp.last_name)as emp_name"
        //            + ", c.contact_name, cp.contact_person_name"
        //            + ", m.method_name"
        //            + ", case when pay.contact_person_seq is not null then cp.contact_person_name"
        //                + " else case when pay.contact_seq is not null then c.contact_name"
        //                    + " else concat(np.prefix_short, emp.first_name, ' ', emp.last_name)"
        //                    + " end"
        //                + " end as payable_name"

        //            + ", mr.money_req_name, pt.petition_no, pt.ref_no as petition_ref_no"

        //            + ", pay.approved_by, pay.approved_when, pay.record_status, rs.record_status_name"
        //            + ", pay.created_by, pay.created_when, pay.updated_by, pay.updated_when"
        //            + " FROM fim_payments pay"
        //            + " LEFT JOIN bgm_mas_source s ON pay.bgm_source_seq = s.bgm_source_seq"
        //            + " LEFT JOIN fim_mas_methods m ON pay.method_seq = m.method_seq"
        //            + " LEFT JOIN fim_money_requests mr ON pay.money_req_seq = mr.money_req_seq"

        //            + " LEFT JOIN fim_petition_dtls ptd ON pay.petition_dtls_seq = ptd.petition_dtls_seq"
        //            + " LEFT JOIN fim_petitions pt ON ptd.petition_seq = pt.petition_seq"
        //            + " LEFT JOIN fim_mas_contacts c ON pay.contact_seq = c.contact_seq"
        //            + " LEFT JOIN fim_mas_contact_persons cp ON pay.contact_person_seq = cp.contact_person_seq"
        //            //bidder_seq
        //            //po_seq
        //            //+ " LEFT JOIN fim_payments post ON pay.post_pay_seq = post.pay_seq"
        //            //+ " LEFT JOIN fim_payments tax ON pay.tax_pay_seq = tax.pay_seq"

        //            + " LEFT JOIN hrm_ps_employees emp ON pay.emp_seq = emp.emp_seq"
        //            + " LEFT JOIN mas_name_prefixes np on emp.name_prefix_seq = np.name_prefix_seq"
        //            + " LEFT JOIN hrm_mp_work_areas area ON pay.work_area_seq = area.work_area_seq"
        //            + " LEFT JOIN sys_record_status rs ON pay.record_status = rs.record_status"
        //            + " WHERE pay.pay_seq = @seq";
        //        

        //        drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
        //        if (drc.Count > 0)
        //        {
        //            info.pay_seq = Convert.ToInt32(drc[0]["pay_seq"]);
        //            info.bgm_source_seq = Convert.ToInt32(drc[0]["bgm_source_seq"]);
        //            info.work_area_seq = Convert.ToInt32(drc[0]["work_area_seq"]);
        //            info.bgm_year = Convert.ToInt32(drc[0]["bgm_year"]);
        //            info.event_seq = cn.ConvertNullInt(drc[0]["event_seq"]);
        //            info.pay_date = cn.ConvertNullDateTime(drc[0]["pay_date"]);
        //            info.real_pay_date = cn.ConvertNullDateTime(drc[0]["real_pay_date"]);
        //            info.ref_no = drc[0]["ref_no"].ToString();
        //            info.receipt_no = drc[0]["receipt_no"].ToString();
        //            info.receipt_name = drc[0]["receipt_name"].ToString();
        //            info.pay_name = drc[0]["pay_name"].ToString();
        //            info.method_seq = cn.ConvertNullInt(drc[0]["method_seq"]);
        //            info.money_req_seq = cn.ConvertNullInt(drc[0]["money_req_seq"]);
        //            info.petition_seq = cn.ConvertNullInt(drc[0]["petition_seq"]);
        //            info.petition_dtls_seq = cn.ConvertNullInt(drc[0]["petition_dtls_seq"]);
        //            info.emp_seq = cn.ConvertNullInt(drc[0]["emp_seq"]);
        //            info.contact_seq = cn.ConvertNullInt(drc[0]["contact_seq"]);
        //            info.bidder_seq = cn.ConvertNullInt(drc[0]["bidder_seq"]);
        //            info.po_seq = cn.ConvertNullInt(drc[0]["po_seq"]);
        //            info.amount = cn.ConvertNullDouble(drc[0]["amount"]);
        //            info.vat_rate = cn.ConvertNullDouble(drc[0]["vat_rate"]);
        //            info.vat = cn.ConvertNullDouble(drc[0]["vat"]);
        //            info.tax_rate = cn.ConvertNullDouble(drc[0]["tax_rate"]);
        //            info.tax = cn.ConvertNullDouble(drc[0]["tax"]);
        //            info.post_pay_seq = cn.ConvertNullInt(drc[0]["post_pay_seq"]);
        //            info.tax_pay_seq = cn.ConvertNullInt(drc[0]["tax_pay_seq"]);

        //            info.bgm_source_name = drc[0]["bgm_source_name"].ToString();
        //            info.work_area_name = drc[0]["work_area_name"].ToString();
        //            info.method_name = drc[0]["method_name"].ToString();
        //            info.money_req_name = drc[0]["money_req_name"].ToString();
        //            info.petition_no = drc[0]["petition_no"].ToString();
        //            //info.petition_ref_no = drc[0]["petition_ref_no"].ToString();
        //            info.emp_name = drc[0]["emp_name"].ToString();
        //            info.contact_name = drc[0]["contact_name"].ToString();
        //            info.contact_person_name = drc[0]["contact_person_name"].ToString();
        //            info.payable_name = drc[0]["payable_name"].ToString();

        //            info.approved_by = cn.ConvertNullInt(drc[0]["approved_by"]);
        //            info.approved_when = cn.ConvertNullDateTime(drc[0]["approved_when"]);

        //            info.record_status = drc[0]["RECORD_STATUS"].ToString();
        //            info.record_status_name = drc[0]["RECORD_STATUS_NAME"].ToString();
        //            info.created_by = cn.ConvertNullInt(drc[0]["CREATED_BY"]);
        //            info.created_when = cn.ConvertNullDateTime(drc[0]["CREATED_WHEN"]);
        //            info.updated_by = cn.ConvertNullInt(drc[0]["UPDATED_BY"]);
        //            info.updated_when = cn.ConvertNullDateTime(drc[0]["UPDATED_WHEN"]);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw (ex);
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return info;
        //}

        //public M_FIM_Payments GetInfoFromMoneyReqSeq(int money_req_seq)
        //{
        //    string strSQL;
        //    DataRowCollection drc = null;
        //    M_FIM_Payments info = new M_FIM_Payments();
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(2);

        //        dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
        //        dbManager.AddParameters(1, "@money_req_seq", money_req_seq);

        //        strSQL = "SELECT pay.pay_seq, pay.bgm_source_seq, pay.work_area_seq, pay.bgm_year"
        //            + ", pay.event_seq, pay.pay_date, pay.real_pay_date, pay.ref_no"
        //            + ", pay.receipt_no, pay.receipt_name, pay.pay_name, pay.method_seq"
        //            + ", pay.money_req_seq, pay.petition_seq, pay.petition_dtls_seq"
        //            + ", pay.emp_seq, pay.contact_seq, pay.contact_person_seq, pay.bidder_seq, pay.po_seq"
        //            + ", pay.amount, pay.vat_rate, pay.vat, pay.tax_rate, pay.tax"
        //            + ", pay.post_pay_seq, pay.tax_pay_seq"

        //            + ", s.bgm_source_name, area.work_area_name"
        //            + ", concat(np.prefix_short, emp.first_name, ' ', emp.last_name)as emp_name"
        //            + ", c.contact_name, cp.contact_person_name"
        //            + ", m.method_name"
        //            + ", case when pay.contact_person_seq is not null then cp.contact_person_name"
        //                + " else case when pay.contact_seq is not null then c.contact_name"
        //                    + " else concat(np.prefix_short, emp.first_name, ' ', emp.last_name)"
        //                    + " end"
        //                + " end as payable_name"

        //            + ", mr.money_req_name, pt.petition_no, pt.ref_no as petition_ref_no"

        //            + ", pay.approved_by, pay.approved_when, pay.record_status, rs.record_status_name"
        //            + ", pay.created_by, pay.created_when, pay.updated_by, pay.updated_when"
        //            + " FROM fim_payments pay"
        //            + " LEFT JOIN bgm_mas_source s ON pay.bgm_source_seq = s.bgm_source_seq"
        //            + " LEFT JOIN fim_mas_methods m ON pay.method_seq = m.method_seq"
        //            + " LEFT JOIN fim_money_requests mr ON pay.money_req_seq = mr.money_req_seq"

        //            + " LEFT JOIN fim_petition_dtls ptd ON pay.petition_dtls_seq = ptd.petition_dtls_seq"
        //            + " LEFT JOIN fim_petitions pt ON ptd.petition_seq = pt.petition_seq"
        //            + " LEFT JOIN fim_mas_contacts c ON pay.contact_seq = c.contact_seq"
        //            + " LEFT JOIN fim_mas_contact_persons cp ON pay.contact_person_seq = cp.contact_person_seq"
        //            //bidder_seq
        //            //po_seq
        //            //+ " LEFT JOIN fim_payments post ON pay.post_pay_seq = post.pay_seq"
        //            //+ " LEFT JOIN fim_payments tax ON pay.tax_pay_seq = tax.pay_seq"

        //            + " LEFT JOIN hrm_ps_employees emp ON pay.emp_seq = emp.emp_seq"
        //            + " LEFT JOIN mas_name_prefixes np on emp.name_prefix_seq = np.name_prefix_seq"
        //            + " LEFT JOIN hrm_mp_work_areas area ON pay.work_area_seq = area.work_area_seq"
        //            + " LEFT JOIN sys_record_status rs ON pay.record_status = rs.record_status"
        //            + " WHERE pay.money_req_seq = @money_req_seq"
        //            + " and pay.record_status not like @delete_status";
        //        

        //        drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
        //        if (drc.Count > 0)
        //        {
        //            info.pay_seq = Convert.ToInt32(drc[0]["pay_seq"]);
        //            info.bgm_source_seq = Convert.ToInt32(drc[0]["bgm_source_seq"]);
        //            info.work_area_seq = Convert.ToInt32(drc[0]["work_area_seq"]);
        //            info.bgm_year = Convert.ToInt32(drc[0]["bgm_year"]);
        //            info.event_seq = cn.ConvertNullInt(drc[0]["event_seq"]);
        //            info.pay_date = cn.ConvertNullDateTime(drc[0]["pay_date"]);
        //            info.real_pay_date = cn.ConvertNullDateTime(drc[0]["real_pay_date"]);
        //            info.ref_no = drc[0]["ref_no"].ToString();
        //            info.receipt_no = drc[0]["receipt_no"].ToString();
        //            info.receipt_name = drc[0]["receipt_name"].ToString();
        //            info.pay_name = drc[0]["pay_name"].ToString();
        //            info.method_seq = cn.ConvertNullInt(drc[0]["method_seq"]);
        //            info.money_req_seq = cn.ConvertNullInt(drc[0]["money_req_seq"]);
        //            info.petition_seq = cn.ConvertNullInt(drc[0]["petition_seq"]);
        //            info.petition_dtls_seq = cn.ConvertNullInt(drc[0]["petition_dtls_seq"]);
        //            info.emp_seq = cn.ConvertNullInt(drc[0]["emp_seq"]);
        //            info.contact_seq = cn.ConvertNullInt(drc[0]["contact_seq"]);
        //            info.bidder_seq = cn.ConvertNullInt(drc[0]["bidder_seq"]);
        //            info.po_seq = cn.ConvertNullInt(drc[0]["po_seq"]);
        //            info.amount = cn.ConvertNullDouble(drc[0]["amount"]);
        //            info.vat_rate = cn.ConvertNullDouble(drc[0]["vat_rate"]);
        //            info.vat = cn.ConvertNullDouble(drc[0]["vat"]);
        //            info.tax_rate = cn.ConvertNullDouble(drc[0]["tax_rate"]);
        //            info.tax = cn.ConvertNullDouble(drc[0]["tax"]);
        //            info.post_pay_seq = cn.ConvertNullInt(drc[0]["post_pay_seq"]);
        //            info.tax_pay_seq = cn.ConvertNullInt(drc[0]["tax_pay_seq"]);

        //            info.bgm_source_name = drc[0]["bgm_source_name"].ToString();
        //            info.work_area_name = drc[0]["work_area_name"].ToString();
        //            info.method_name = drc[0]["method_name"].ToString();
        //            info.money_req_name = drc[0]["money_req_name"].ToString();
        //            info.petition_no = drc[0]["petition_no"].ToString();
        //            //info.petition_ref_no = drc[0]["petition_ref_no"].ToString();
        //            info.emp_name = drc[0]["emp_name"].ToString();
        //            info.contact_name = drc[0]["contact_name"].ToString();
        //            info.contact_person_name = drc[0]["contact_person_name"].ToString();
        //            info.payable_name = drc[0]["payable_name"].ToString();

        //            info.approved_by = cn.ConvertNullInt(drc[0]["approved_by"]);
        //            info.approved_when = cn.ConvertNullDateTime(drc[0]["approved_when"]);

        //            info.record_status = drc[0]["RECORD_STATUS"].ToString();
        //            info.record_status_name = drc[0]["RECORD_STATUS_NAME"].ToString();
        //            info.created_by = cn.ConvertNullInt(drc[0]["CREATED_BY"]);
        //            info.created_when = cn.ConvertNullDateTime(drc[0]["CREATED_WHEN"]);
        //            info.updated_by = cn.ConvertNullInt(drc[0]["UPDATED_BY"]);
        //            info.updated_when = cn.ConvertNullDateTime(drc[0]["UPDATED_WHEN"]);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw (ex);
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return info;
        //}

        //public IList<M_FIM_Payments> GetListFromPetition(int petition_seq)
        //{
        //    string strSQL;
        //    DataRowCollection drc = null;
        //    IList<M_FIM_Payments> infoList = new List<M_FIM_Payments>();
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(2);

        //        dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
        //        dbManager.AddParameters(1, "@seq", petition_seq);

        //        strSQL = "SELECT pay.pay_seq, pay.bgm_source_seq, pay.work_area_seq, pay.bgm_year"
        //            + ", pay.event_seq, pay.pay_date, pay.real_pay_date, pay.ref_no"
        //            + ", pay.receipt_no, pay.receipt_name, pay.pay_name, pay.method_seq"
        //            + ", pay.money_req_seq, pay.petition_seq, pay.petition_dtls_seq"
        //            + ", pay.emp_seq, pay.contact_seq, pay.contact_person_seq, pay.bidder_seq, pay.po_seq"
        //            + ", pay.amount, pay.vat_rate, pay.vat, pay.tax_rate, pay.tax"
        //            + ", pay.post_pay_seq, pay.tax_pay_seq"

        //            + ", s.bgm_source_name, area.work_area_name"
        //            + ", concat(np.prefix_short, emp.first_name, ' ', emp.last_name)as emp_text"
        //            + ", c.contact_name, cp.contact_person_name"
        //            + ", case when pay.method_seq = '1' then 'เงินสด'"
        //                + " else case when pay.method_seq = '2' then 'เช็ค'"
        //                    + " else case when pay.method_seq = '3' then 'โอน'"
        //                        + " else 'ดราฟท์'"
        //                        + " end"
        //                    + " end"
        //                + " end as method_name"
        //            + ", case when pay.contact_person_seq is not null then cp.contact_person_name"
        //                + " else case when pay.contact_seq is not null then c.contact_name"
        //                    + " else concat(np.prefix_short, emp.first_name, ' ', emp.last_name)"
        //                    + " end"
        //                + " end as payable_name"

        //            + ", pay.approved_by, pay.approved_when, pay.record_status, rs.record_status_name"
        //            + ", pay.created_by, pay.created_when, pay.updated_by, pay.updated_when"
        //            + " FROM fim_payments pay"
        //            + " LEFT JOIN bgm_mas_source s ON pay.bgm_source_seq = s.bgm_source_seq"
        //            //+ " LEFT JOIN fim_money_requests mr ON pay.money_req_seq = mr.money_req_seq"
        //            //+ " LEFT JOIN fim_petitions pt ON pay.petition_seq = pt.petition_seq"
        //            //+ " LEFT JOIN fim_petitions ptd ON pay.petition_dtls_seq = ptd.petition_dtls_seq"
        //            + " LEFT JOIN fim_mas_contacts c ON pay.contact_seq = c.contact_seq"
        //            + " LEFT JOIN fim_mas_contact_persons cp ON pay.contact_person_seq = cp.contact_person_seq"
        //            //bidder_seq
        //            //po_seq
        //            //+ " LEFT JOIN fim_payments post ON pay.post_pay_seq = post.pay_seq"
        //            //+ " LEFT JOIN fim_payments tax ON pay.tax_pay_seq = tax.pay_seq"

        //            + " LEFT JOIN hrm_ps_employees emp ON pay.emp_seq = emp.emp_seq"
        //            + " LEFT JOIN mas_name_prefixes np on emp.name_prefix_seq = np.name_prefix_seq"
        //            + " LEFT JOIN hrm_mp_work_areas area ON pay.work_area_seq = area.work_area_seq"
        //            + " LEFT JOIN sys_record_status rs ON pay.record_status = rs.record_status"
        //            + " WHERE pay.petition_seq = @seq";
        //        

        //        drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
        //        if (drc.Count > 0)
        //        {
        //            for (int i = 0; i < drc.Count; i++)
        //            {
        //                M_FIM_Payments info = new M_FIM_Payments();
        //                info.pay_seq = Convert.ToInt32(drc[0]["pay_seq"]);
        //                info.bgm_source_seq = Convert.ToInt32(drc[0]["bgm_source_seq"]);
        //                info.work_area_seq = Convert.ToInt32(drc[0]["work_area_seq"]);
        //                info.bgm_year = Convert.ToInt32(drc[0]["bgm_year"]);
        //                info.event_seq = cn.ConvertNullInt(drc[0]["event_seq"]);
        //                info.pay_date = cn.ConvertNullDateTime(drc[0]["pay_date"]);
        //                info.real_pay_date = cn.ConvertNullDateTime(drc[0]["real_pay_date"]);
        //                info.ref_no = drc[0]["ref_no"].ToString();
        //                info.receipt_no = drc[0]["receipt_no"].ToString();
        //                info.receipt_name = drc[0]["receipt_name"].ToString();
        //                info.pay_name = drc[0]["pay_name"].ToString();
        //                info.method_seq = cn.ConvertNullInt(drc[0]["method_seq"]);
        //                info.money_req_seq = cn.ConvertNullInt(drc[0]["money_req_seq"]);
        //                info.petition_seq = cn.ConvertNullInt(drc[0]["petition_seq"]);
        //                info.petition_dtls_seq = cn.ConvertNullInt(drc[0]["petition_dtls_seq"]);
        //                info.emp_seq = cn.ConvertNullInt(drc[0]["emp_seq"]);
        //                info.contact_seq = cn.ConvertNullInt(drc[0]["contact_seq"]);
        //                info.bidder_seq = cn.ConvertNullInt(drc[0]["bidder_seq"]);
        //                info.po_seq = cn.ConvertNullInt(drc[0]["po_seq"]);
        //                info.amount = cn.ConvertNullDouble(drc[0]["amount"]);
        //                info.vat_rate = cn.ConvertNullDouble(drc[0]["vat_rate"]);
        //                info.vat = cn.ConvertNullDouble(drc[0]["vat"]);
        //                info.tax_rate = cn.ConvertNullDouble(drc[0]["tax_rate"]);
        //                info.tax = cn.ConvertNullDouble(drc[0]["tax"]);
        //                info.post_pay_seq = cn.ConvertNullInt(drc[0]["post_pay_seq"]);
        //                info.tax_pay_seq = cn.ConvertNullInt(drc[0]["tax_pay_seq"]);

        //                info.bgm_source_name = drc[0]["bgm_source_name"].ToString();
        //                info.work_area_name = drc[0]["work_area_name"].ToString();
        //                info.method_name = drc[0]["method_name"].ToString();
        //                info.money_req_name = drc[0]["money_req_name"].ToString();
        //                info.petition_no = drc[0]["petition_no"].ToString();
        //                info.petition_dtls_no = drc[0]["petition_dtls_no"].ToString();
        //                info.emp_name = drc[0]["emp_name"].ToString();
        //                info.contact_name = drc[0]["contact_name"].ToString();
        //                info.contact_person_name = drc[0]["contact_person_name"].ToString();
        //                info.payable_name = drc[0]["payable_name"].ToString();

        //                info.approved_by = cn.ConvertNullInt(drc[0]["approved_by"]);
        //                info.approved_when = cn.ConvertNullDateTime(drc[0]["approved_when"]);

        //                info.record_status = drc[0]["RECORD_STATUS"].ToString();
        //                info.record_status_name = drc[0]["RECORD_STATUS_NAME"].ToString();
        //                info.created_by = cn.ConvertNullInt(drc[0]["CREATED_BY"]);
        //                info.created_when = cn.ConvertNullDateTime(drc[0]["CREATED_WHEN"]);
        //                info.updated_by = cn.ConvertNullInt(drc[0]["UPDATED_BY"]);
        //                info.updated_when = cn.ConvertNullDateTime(drc[0]["UPDATED_WHEN"]);

        //                infoList.Add(info);
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw (ex);
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return infoList;
        //}

        ////public string SelectRecentInsertedRoleSeq()
        ////{
        ////    string strSQL;
        ////    string strResult;

        ////    try
        ////    {
        ////        dbManager.Open();

        ////        strSQL = "select scope_identity() as last_seq";

        ////        strResult = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows[0]["last_seq"].ToString();
        ////    }
        ////    catch
        ////    {
        ////        throw;
        ////    }
        ////    finally
        ////    {
        ////        dbManager.Dispose();
        ////    }

        ////    return strResult;
        ////}

        //public void ChangeStatus(M_FIM_Payments info)
        //{
        //    string strSQL;
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(4);

        //        dbManager.AddParameters(0, "@pay_seq", info.pay_seq);
        //        dbManager.AddParameters(1, "@record_status", info.record_status);
        //        dbManager.AddParameters(2, "@updated_by", info.updated_by);
        //        dbManager.AddParameters(3, "@updated_when", info.updated_when);

        //        strSQL = "UPDATE fim_payments"
        //            + " SET record_status = @record_status"
        //            + ", updated_by = @updated_by"
        //            + ", updated_when = @updated_when"
        //            + " WHERE pay_seq = @pay_seq";

        //        dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }
        //}

        //public void UpdateReceipt(M_FIM_Payments info)
        //{
        //    string strSQL;
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(6);

        //        dbManager.AddParameters(0, "@pay_seq", info.pay_seq);
        //        dbManager.AddParameters(1, "@real_pay_date", info.real_pay_date);
        //        dbManager.AddParameters(2, "@receipt_no", info.receipt_no);
        //        dbManager.AddParameters(3, "@receipt_name", info.receipt_name);
        //        dbManager.AddParameters(4, "@updated_by", info.updated_by);
        //        dbManager.AddParameters(5, "@updated_when", info.updated_when);

        //        strSQL = "UPDATE fim_payments"
        //            + " SET real_pay_date = @real_pay_date"
        //            + ", receipt_no = @receipt_no"
        //            + ", receipt_name = @receipt_name"
        //            + ", updated_by = @updated_by"
        //            + ", updated_when = @updated_when"
        //            + " WHERE pay_seq = @pay_seq";

        //        dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }
        //}

        //public DataTable Report_SumUpPayment(Nullable<DateTime> date)
        //{
        //    string strSQL;
        //    DataTable dtb = null;
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(2);

        //        dbManager.AddParameters(0, "@date", date);
        //        dbManager.AddParameters(1, "@record_status", SystemInfo._DeleteRecordStatus);

        //        strSQL = "SELECT p.ref_no, p.pay_name"
        //            + ", p.pay_date"
        //            + ", case when p.contact_person_seq is not null then cp.contact_person_name"
        //                + " else case when p.contact_seq is not null then c.contact_name"
        //                    + " else concat(np.prefix_short, emp.first_name, ' ', emp.last_name)"
        //                    + " end"
        //                + " end as payee_name"
        //            + ", p.amount, che.cheque_no"
        //            + " FROM fim_payments p"
        //            + " LEFT JOIN fim_payment_cheques pc ON p.pay_seq = pc.pay_seq"
        //            + " LEFT JOIN fim_cheques che ON pc.cheque_seq = che.cheque_seq"
        //            + " LEFT JOIN fim_mas_contacts c ON p.contact_seq = c.contact_seq"
        //            + " LEFT JOIN fim_mas_contact_persons cp ON p.contact_person_seq = cp.contact_person_seq"
        //            + " LEFT JOIN hrm_ps_employees emp ON p.emp_seq = emp.emp_seq"
        //            + " LEFT JOIN mas_name_prefixes np on emp.name_prefix_seq = np.name_prefix_seq"
        //            + " WHERE p.pay_date = @date"
        //            + " AND p.record_status not like @record_status";
        //        

        //        dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
        //    }
        //    catch (Exception ex)
        //    {
        //        throw (ex);
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return dtb;
        //}

        //public string GetNextRefNo(Nullable<int> bgm_year, Nullable<int> bgm_source_seq)//, string use_advance)
        //{
        //    string strSQL;
        //    DataTable dtb = null;
        //    string strRefNo = "";
        //    string strResult = bgm_year.ToString() + "/0001"; ;
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(3);

        //        dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
        //        dbManager.AddParameters(1, "@bgm_source_seq", bgm_source_seq);
        //        dbManager.AddParameters(2, "@bgm_year", bgm_year);

        //        strSQL = "SELECT mr.bgm_source_seq, mr.bgm_year, max(mr.ref_no) as ref_no"
        //            + " FROM fim_payments mr"
        //            + " WHERE mr.record_status not like @delete_status"
        //            + (bgm_source_seq != null ? " and mr.bgm_source_seq = @bgm_source_seq" : "")
        //            + (bgm_year != null ? "" : " and mr.bgm_year = @bgm_year")
        //            + " group by mr.bgm_source_seq, mr.bgm_year";
        //        

        //        dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
        //        if (dtb.Rows.Count > 0)
        //        {
        //            strRefNo = dtb.Rows[0]["ref_no"].ToString();

        //            if (strRefNo.Length > 0)
        //            {
        //                strRefNo = strRefNo.Split('/')[1];
        //                int nSequnce = Convert.ToInt32(strRefNo);
        //                strResult = bgm_year.ToString() + "/" + (nSequnce + 1).ToString("0000");
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw (ex);
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return strResult;
        //}


        //public IList<M_FIM_Payments> GetNotRealPayment(int? bgm_source_seq, int? work_area_seq, int? bgm_year, int? method_seq)
        //{
        //    string strSQL;
        //    DataRowCollection drc = null;
        //    IList<M_FIM_Payments> infoList = new List<M_FIM_Payments>();
        //    try
        //    {
        //        dbManager.Open();
        //        dbManager.CreateParameters(5);

        //        dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
        //        dbManager.AddParameters(1, "@bgm_source_seq", bgm_source_seq);
        //        dbManager.AddParameters(2, "@work_area_seq", work_area_seq);
        //        dbManager.AddParameters(3, "@bgm_year", bgm_year);
        //        dbManager.AddParameters(4, "@method_seq", method_seq);

        //        //strSQL = "";
        //        strSQL = "SELECT p.pay_seq, p.bgm_source_seq, p.work_area_seq, p.bgm_year, p.method_seq"
        //            + ", p.pay_date, p.real_pay_date, p.pay_name, p.money_req_seq, p.amount, p.contact_seq"
        //            + ", rs.record_status_name, m.method_name, s.bgm_source_name, mr.money_req_name, c.NameTh"
        //            + " FROM fim_payments p"
        //                + " LEFT JOIN fim_mas_methods m ON r.method_seq = m.method_seq"
        //                + " LEFT JOIN IcmMasContact c ON p.contact_seq = c.ConId"
        //                + " LEFT JOIN bgm_mas_source s ON p.bgm_source_seq = s.bgm_source_seq"
        //                + " LEFT JOIN fim_money_requests mr ON p.money_req_seq = mr.money_req_seq"
        //                + " LEFT JOIN sys_record_status rs ON p.record_status = rs.record_status"
        //                + " LEFT JOIN fim_payments_payinpack pp ON p.pay_seq = rs.record_status"
        //            + " WHERE p.record_status not like 'D'"
        //            + " AND NOT EXISTS (SELECT * FROM fim_payments_payinpack pp WHERE  p.pay_seq = pp.pay_seq)"                   
        //            + (bgm_source_seq != null ? " AND p.bgm_source_seq = @bgm_source_seq" : "")
        //            + (work_area_seq != null ? " AND p.work_area_seq = @work_area_seq" : "")
        //            + (bgm_year != null ? " AND p.bgm_year = @bgm_year" : "")
        //            + (method_seq != null ? " AND p.method_seq = @method_seq" : "")
        //            + " ORDER BY p.pay_seq, p.pay_date";

                
        //        drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
        //        if (drc.Count > 0)
        //        {
        //            for (int i = 0; i < drc.Count; i++)
        //            {
        //                M_FIM_Payments info = new M_FIM_Payments();
        //                info.pay_seq = Convert.ToInt32(drc[i]["pay_seq"]);
        //                info.bgm_source_seq = Convert.ToInt32(drc[i]["bgm_source_seq"]); //cn.ConvertNullInt(drc[i]["bgm_source_seq"]);
        //                info.work_area_seq = Convert.ToInt32(drc[i]["work_area_seq"]);
        //                info.bgm_year = Convert.ToInt32(drc[i]["bgm_year"]);
        //                info.method_seq = cn.ConvertNullInt(drc[i]["method_seq"]);
        //                info.pay_date = cn.ConvertNullDateTime(drc[i]["pay_date"]);
        //                info.real_pay_date = cn.ConvertNullDateTime(drc[i]["real_pay_date"]);
        //                info.pay_name = drc[i]["pay_name"]==null ? "" : drc[i]["pay_name"].ToString();
        //                info.money_req_seq = cn.ConvertNullInt(drc[i]["method_seq"]);
        //                info.amount = cn.ConvertNullDouble(drc[i]["amount"]);
        //                info.contact_seq = cn.ConvertNullInt(drc[i]["contact_seq"]);
        //                info.petition_seq = cn.ConvertNullInt(drc[i]["petition_seq"]);
        //                info.bidder_seq = cn.ConvertNullInt(drc[i]["petition_seq"]);
        //                info.record_status = drc[i]["record_status"] ==null ? "" : drc[i]["record_status"].ToString();
        //                info.record_status_name = drc[i]["record_status_name"] == null ? "" : drc[i]["record_status_name"].ToString();
        //                info.created_by = cn.ConvertNullInt(drc[i]["created_by"]);
        //                info.created_when = cn.ConvertNullDateTime(drc[i]["created_when"]);
        //                info.updated_by = cn.ConvertNullInt(drc[i]["updated_by"]);
        //                info.updated_when = cn.ConvertNullDateTime(drc[i]["updated_when"]);
        //                infoList.Add(info);
        //            }
        //        }

        //        //strSQL = "SELECT r.receive_seq, r.bgm_source_seq, r.work_area_seq, r.bgm_year"
        //        //    + ", r.receive_type_seq, r.receipt_no"
        //        //    + ", r.receive_date, r.manual_receipt, r.receive_mode, r.method_seq"
        //        //    + ", r.cheque_no, r.branch_seq, r.bank_acc_seq, r.contact_seq, r.contact_person_seq"
        //        //    + ", r.emp_seq, r.temp_contact, r.amount, r.currency_seq, r.exchange_rate, r.bath_amount"
        //        //    + ", r.received_by, r.remarks, r.tran_grp_seq, r.deposit_seq"
        //        //    + ", r.petition_seq, r.money_req_seq, r.pay_seq, r.record_status"
        //        //    + ", case when coalesce(r.contact_seq, '') not like '' then c.NameTh"
        //        //        + " else case when coalesce(r.emp_seq, '') not like '' then concat(empnp.prefix_name, emp.first_name, ' ', emp.last_name)"
        //        //            + " else case when coalesce(r.contact_person_seq, '') not like '' then cp.contact_person_name"
        //        //                + " else r.temp_contact"
        //        //                + " end"
        //        //            + " end"
        //        //        + " end as payer_name"
        //        //    + ", r.icm_bid_rec_seq, r.icm_bid_off_col_seq, r.icm_po_con_col_seq, r.icm_po_pre_col_seq"
        //        //    + ", r.icm_dn_pen_seq, r.icm_po_instal_seq, r.icm_stockmm_seq"

        //        //    + ", CASE WHEN r.receive_mode = '1' THEN CONCAT('รับเงินคืนจากรายการรอเบิกที่ ', mr.ref_no)"
        //        //        + " ELSE CASE WHEN r.receive_mode = '3' THEN CONCAT('รับเงินจากรายการขอเบิกที่ ', pt.ref_no)"
        //        //            + " ELSE rt.receive_type_name"
        //        //            + " END"
        //        //        + " END AS receive_type_name"
        //        //    + ", bb.bank_seq, b.bank_id, b.bank_name, bb.branch_id, bb.branch_name"
        //        //    + ", acc.bank_acc_no, acc.bank_acc_name"

        //        //    + ", s.bgm_source_name, area.work_area_name, c.NameTh, cp.contact_person_name"
        //        //    + ", m.method_name, cur.currency_name"
        //        //    + ", concat(empnp.prefix_name, emp.first_name, ' ', emp.last_name) as emp_name"
        //        //    + ", concat(recnp.prefix_name, rec.first_name, ' ', rec.last_name) as received_by_name"
        //        //    + ", rs.record_status_name"
        //        //    + ", r.created_by, r.created_when, r.updated_by, r.updated_when"
        //        //    + " FROM fim_receives r"
        //        //    //+ " LEFT JOIN (select receive_seq"
        //        //    //    //+ ", sum(coalesce(amount, 0)) as total_amount"
        //        //    //    //+ ", currency_seq, exchange_rate"
        //        //    //    + ", sum(coalesce(bath_amount, 0)) as total_bath_amount"
        //        //    //    + " from fim_receive_dtls"
        //        //    //    + " where record_status not like 'D'"
        //        //    //    + " group by receive_seq"//, currency_seq, exchange_rate"
        //        //    //    + ") rd on r.receive_seq = rd.receive_seq"
        //        //    + " LEFT JOIN fim_mas_currencies cur ON r.currency_seq = cur.currency_seq"
        //        //    + " LEFT JOIN fim_mas_receive_types rt ON r.receive_type_seq = rt.receive_type_seq"
        //        //    + " LEFT JOIN fim_mas_methods m ON r.method_seq = m.method_seq"
        //        //    + " LEFT JOIN fim_mas_bank_branchs bb ON r.branch_seq = bb.branch_seq"
        //        //    + " LEFT JOIN fim_mas_banks b ON bb.bank_seq = b.bank_seq"
        //        //    + " LEFT JOIN fim_mas_bank_accounts acc ON r.bank_acc_seq = acc.bank_acc_seq"
                
                
        //        //    + " LEFT JOIN fim_mas_contact_persons cp ON r.contact_person_seq = cp.contact_person_seq"
                
        //        //    + " LEFT JOIN hrm_ps_employees emp ON r.emp_seq = emp.emp_seq"
        //        //    + " LEFT JOIN mas_name_prefixes empnp ON emp.name_prefix_seq = empnp.name_prefix_seq"
        //        //    + " LEFT JOIN hrm_ps_employees rec ON r.received_by = rec.emp_seq"
        //        //    + " LEFT JOIN mas_name_prefixes recnp ON rec.name_prefix_seq = recnp.name_prefix_seq"
        //        //    + " LEFT JOIN hrm_mp_work_areas area ON r.work_area_seq = area.work_area_seq"
                
        //        //    + " WHERE r.record_status not like 'D'"
        //        //    + (bgm_source_seq != null ? " AND r.bgm_source_seq = @bgm_source_seq" : "")
        //        //    + (work_area_seq != null ? " AND r.work_area_seq = @work_area_seq" : "")
        //        //    + (bgm_year != null ? " AND r.bgm_year = @bgm_year" : "")
        //        //    + (pay_seq != null ?
        //        //        " AND ((r.deposit_seq is null AND r.pay_seq is null) OR r.deposit_seq = @transfer_seq)"
        //        //        : " AND (r.deposit_seq is null) AND r.pay_seq is null")
        //        //    + " ORDER BY r.receipt_no, r.receive_date";
        //        //

        //        //drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
        //        //if (drc.Count > 0)
        //        //{
        //        //    for (int i = 0; i < drc.Count; i++)
        //        //    {
        //        //        M_FIM_Receives info = new M_FIM_Receives();
        //        //        info.receive_seq = Convert.ToInt32(drc[i]["receive_seq"]);
        //        //        info.bgm_source_seq = cn.ConvertNullInt(drc[i]["bgm_source_seq"]);
        //        //        info.work_area_seq = cn.ConvertNullInt(drc[i]["work_area_seq"]);
        //        //        info.bgm_year = cn.ConvertNullInt(drc[i]["bgm_year"]);
        //        //        info.receive_type_seq = cn.ConvertNullInt(drc[i]["receive_type_seq"]);
        //        //        info.receipt_no = drc[i]["receipt_no"].ToString();
        //        //        info.receive_date = cn.ConvertNullDateTime(drc[i]["receive_date"]);
        //        //        info.manual_receipt = drc[i]["manual_receipt"].ToString();
        //        //        info.receive_mode = drc[i]["receive_mode"].ToString();
        //        //        info.method_seq = cn.ConvertNullInt(drc[i]["method_seq"]);
        //        //        info.cheque_no = drc[i]["cheque_no"].ToString();
        //        //        info.branch_seq = cn.ConvertNullInt(drc[i]["branch_seq"]);
        //        //        info.bank_acc_seq = cn.ConvertNullInt(drc[i]["bank_acc_seq"]);
        //        //        info.contact_seq = cn.ConvertNullInt(drc[i]["contact_seq"]);
        //        //        info.contact_person_seq = cn.ConvertNullInt(drc[i]["contact_person_seq"]);
        //        //        info.emp_seq = cn.ConvertNullInt(drc[i]["emp_seq"]);
        //        //        info.temp_contact = drc[i]["temp_contact"].ToString();
        //        //        info.amount = cn.ConvertNullDouble(drc[i]["amount"]);
        //        //        info.currency_seq = cn.ConvertNullInt(drc[i]["currency_seq"]);
        //        //        info.exchange_rate = cn.ConvertNullDouble(drc[i]["exchange_rate"]);
        //        //        info.bath_amount = cn.ConvertNullDouble(drc[i]["bath_amount"]);
        //        //        info.received_by = cn.ConvertNullInt(drc[i]["received_by"]);
        //        //        info.remarks = drc[i]["remarks"].ToString();
        //        //        info.tran_grp_seq = cn.ConvertNullInt(drc[i]["tran_grp_seq"]);
        //        //        info.deposit_seq = cn.ConvertNullInt(drc[i]["deposit_seq"]);
        //        //        info.petition_seq = cn.ConvertNullInt(drc[i]["petition_seq"]);
        //        //        info.money_req_seq = cn.ConvertNullInt(drc[i]["money_req_seq"]);
        //        //        info.pay_seq = cn.ConvertNullInt(drc[i]["pay_seq"]);
        //        //        info.payer_name = drc[i]["payer_name"].ToString();
        //        //        info.icm_bid_rec_seq = cn.ConvertNullInt(drc[i]["icm_bid_rec_seq"]);
        //        //        info.icm_bid_off_col_seq = cn.ConvertNullInt(drc[i]["icm_bid_off_col_seq"]);
        //        //        info.icm_po_con_col_seq = cn.ConvertNullInt(drc[i]["icm_po_con_col_seq"]);
        //        //        info.icm_po_pre_col_seq = cn.ConvertNullInt(drc[i]["icm_po_pre_col_seq"]);
        //        //        info.icm_dn_pen_seq = cn.ConvertNullInt(drc[i]["icm_dn_pen_seq"]);
        //        //        info.icm_po_instal_seq = cn.ConvertNullInt(drc[i]["icm_po_instal_seq"]);
        //        //        info.icm_stockmm_seq = cn.ConvertNullInt(drc[i]["icm_stockmm_seq"]);
        //        //        info.receive_type_name = drc[i]["receive_type_name"].ToString();
        //        //        info.bgm_source_name = drc[i]["bgm_source_name"].ToString();
        //        //        info.work_area_name = drc[i]["work_area_name"].ToString();
        //        //        info.contact_name = drc[i]["contact_name"].ToString();
        //        //        info.contact_person_name = drc[i]["contact_person_name"].ToString();
        //        //        info.method_name = drc[i]["method_name"].ToString();
        //        //        info.currency_name = drc[i]["currency_name"].ToString();
        //        //        info.bank_seq = cn.ConvertNullInt(drc[i]["bank_seq"]);
        //        //        info.bank_id = drc[i]["bank_id"].ToString();
        //        //        info.bank_name = drc[i]["bank_name"].ToString();
        //        //        info.branch_id = drc[i]["branch_id"].ToString();
        //        //        info.branch_name = drc[i]["branch_name"].ToString();
        //        //        info.bank_acc_no = drc[i]["bank_acc_no"].ToString();
        //        //        info.bank_acc_name = drc[i]["bank_acc_name"].ToString();
        //        //        info.emp_name = drc[i]["emp_name"].ToString();
        //        //        info.received_by_name = drc[i]["received_by_name"].ToString();

        //        //        info.record_status = drc[i]["record_status"].ToString();
        //        //        info.record_status_name = drc[i]["record_status_name"].ToString();
        //        //        info.created_by = cn.ConvertNullInt(drc[i]["created_by"]);
        //        //        info.created_when = cn.ConvertNullDateTime(drc[i]["created_when"]);
        //        //        info.updated_by = cn.ConvertNullInt(drc[i]["updated_by"]);
        //        //        info.updated_when = cn.ConvertNullDateTime(drc[i]["updated_when"]);
        //        //        infoList.Add(info);
        //        //    }
        //        //}
        //    }
        //    catch (Exception ex)
        //    {
        //        throw (ex);
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return infoList;
        //    //throw new NotImplementedException();
        //}
    }
}
